import Vue from 'vue'
import VueRouter from 'vue-router'
import Film from '../views/Film.vue'
import Cinema from '../views/Cinema.vue'
// import Center from '../views/Center.vue'
import Detail from '../views/Detail.vue'
import City from '../views/City.vue'
import Search from '../views/Search.vue'
// import Login from '../views/login.vue'

import Nowplaying from '../views/film/Nowplaying'
import Comingsoon from '../views/film/Comingsoon'
Vue.use(VueRouter) // 注册模块,已经全局创建组件 router-view

const routes = [
  {
    path: '/film',
    component: Film,
    // 嵌套路由
    children: [
      {
        path: 'nowplaying', // 简写
        component: Nowplaying
      },
      {
        path: '/film/comingsoon',
        component: Comingsoon
      },
      {
        path: '',
        redirect: '/film/nowplaying'
      }
    ]
  },

  {
    path: '/cinema',
    component: Cinema
  },
  {
    path: '/cinema/search',
    component: Search
  },
  {
    path: '/city',
    component: City
  },
  {
    path: '/center',
    component: () => import(/* webpackChunkName: "caibigroup" */ '../views/Center.vue')
  },
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "caibigroup" */ '../views/login.vue')// 路由懒加载
  },
  {
    path: '/detail/:myid', // 动态路由
    component: Detail,
    name: 'caibiDetail'
  },
  /* {
    path:'/detail',
    component:Detail
  }, */
  {
    path: '*', // 通配符
    redirect: '/film'
  }
]

const router = new VueRouter({
  mode: 'hash', // hash, history
  routes
})
// 全局路由守卫
/* router.beforeEach((to,from,next) => {
  //...
  let auth = ['/cinema','/order','/money','/card']
  if(auth.includes(to.fullPath)){
    //console.log(localStorage.token)
    if(!localStorage.getItem('token')){
      next('/login')
    }else{
      next()
    }
  }else{
    next()
  }
  //next()  任何路由都放行
  /* if(to.fullPath === '/cinema'){ //局部路由守卫
    console.log('验证token')
  }else{
    next()
  } */
// })

export default router
